const express = require("express");
const app = express();
const path = require("path");
const cors = require('cors');

//引入路由
const homeRouter = require('./Router/homeRouter');
const detailRouter = require('./Router/detailRouter')
const categoryRouter = require('./Router/categoryRouter');
const profileRouter = require('./Router/profileRouter')

//指定静态资源目录 以及跨域中间件
app.use('/static', express.static(path.join(__dirname, 'public')));
app.use(cors());

//挂载路由
app.use('/home',homeRouter);
app.use('/detail',detailRouter);
app.use('/category',categoryRouter);
app.use('/profile',profileRouter);

app.get('/', function (req, res) {
  res.send("Hello world");
});



// 首页商品请求
// app.get('/home/goods', (req, res) => {
//   let data = [];
//   let over = 4;
//   if (req.query.page >= 4) {
//     console.log("......")
//     req.query.page = 4;
//   }
//     // console.log("req.query.page",req.query.page);
//      over = req.query.page * 4;
//     // console.log("over的值",over);
 
//   for (let i = 0; i < over; i++) {
//     data.push(goods[req.query.type].list[i]);
//   }
//   res.send(data);
// })

app.listen(3000, () => {
  console.log("服务器启动在3000端口 可以通过http://localhost:3000 访问");
})